package com.htudata.transctAlarm.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class TransctAlarmServiceDemo {

  private List<Map<String, Object>> result = new ArrayList<>();
  
  public Object updateAlarmStatus() {
    Map<String, Object> result = new HashMap<>();
    result.put("result", Integer.valueOf(1));
    return result;
  }
  
  public Object getAlarmLevels(String a2) {
    if (!this.result.isEmpty())
      return this.result; 
    Map<String, Object> map = new HashMap<>();
    map.put("alarmLevelId", Integer.valueOf(1));
    map.put("name", "完全正常");
    map.put("color", "#0eb84e");
    map.put("level", Integer.valueOf(1));
    this.result.add(map);
    map = new HashMap<>();
    map.put("alarmLevelId", Integer.valueOf(2));
    map.put("name", "基本正常");
    map.put("color", "#00ccff");
    map.put("level", Integer.valueOf(2));
    this.result.add(map);
    map = new HashMap<>();
    map.put("alarmLevelId", Integer.valueOf(3));
    map.put("name", "不太正常");
    map.put("color", "#3366ff");
    map.put("level", Integer.valueOf(3));
    this.result.add(map);
    map = new HashMap<>();
    map.put("alarmLevelId", Integer.valueOf(4));
    map.put("name", "存疑");
    map.put("color", "#ff6501");
    map.put("level", Integer.valueOf(4));
    this.result.add(map);
    map = new HashMap<>();
    map.put("alarmLevelId", Integer.valueOf(5));
    map.put("name", "轻度警告");
    map.put("color", "#d6ce14");
    map.put("level", Integer.valueOf(5));
    this.result.add(map);
    map = new HashMap<>();
    map.put("alarmLevelId", Integer.valueOf(6));
    map.put("name", "一般警告");
    map.put("color", "#cc00ff");
    map.put("level", Integer.valueOf(6));
    this.result.add(map);
    map = new HashMap<>();
    map.put("alarmLevelId", Integer.valueOf(7));
    map.put("name", "严重警告");
    map.put("color", "#cd2920");
    map.put("level", Integer.valueOf(7));
    this.result.add(map);
    return this.result;
  }
  
  public Object updateAlarmLevels(JSONObject params) {
    JSONArray JSONArray = params.getJSONArray("list");
    for (Object object : JSONArray) {
      JSONObject jSONObject = (JSONObject)object;
      int alarmLevelId = ((JSONObject)object).getIntValue("alarmLevelId");
      for (Map<String, Object> map : this.result) {
        int alarmLevelId2 = ((Integer)map.get("alarmLevelId")).intValue();
        if (alarmLevelId == alarmLevelId2) {
          try {
            if (!StringUtils.isBlank(((JSONObject)object).getString("name")))
              map.put("name", ((JSONObject)object).getString("name")); 
          } catch (Exception exception) {}
          try {
            if (!StringUtils.isBlank(((JSONObject)object).getString("color")))
              map.put("color", ((JSONObject)object).getString("color")); 
          } catch (Exception exception) {}
        } 
      } 
    } 
    Map<String, Object> result = new HashMap<>();
    result.put("result", Integer.valueOf(1));
    return result;
  }
}
